package org.example.basic.lambda.collectors;



import org.example.basic.entity.UserEntity;
import org.example.basic.entity.UserEntityList;
import java.util.IntSummaryStatistics;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Copyright (C), 2022, szw
 * FileName: SummarizingTest
 *
 * @author songyafei
 * Date:     2022/1/17 15:42
 * Description: 一次性获取最大，最新，平均等
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
public class SummarizingTest {
    public static void main(String[] args) {
        List<UserEntity> item = UserEntityList.getItem();

        /**
         * 一次性获取最小，最大，总和，平均，数量
         * 支持double，long，int
         */
        IntSummaryStatistics c = item.stream().collect(Collectors.summarizingInt(UserEntity::getAge));
        System.out.println(c.getMin());
        System.out.println(c.getSum());
        System.out.println(c.getAverage());
        System.out.println(c.getCount());
        System.out.println(c.getMax());


    }
}
